<template>
	<div class="">
		<bread-crumb>賽事管理</bread-crumb>
		<div class="uc-body" v-loading="loading" v-if="this.isSuperUser">
			<!--篩選控制-->
			<div class="manage-list-control">
				<!--請注意：覆核中的賽事，狀態也是 >>"進行中"。（1）覆核通過就賽事狀態結束了。（2）足球狀態從打開投注，的投注進行中，到待覆核中的審核，這段時間內，狀態都是沒改變的·  -->
				<el-button type="success" size="small" @click="reFresh" >刷新</el-button>
				<div class="c-blue">註：已開獎成功的則無法作廢</div>
			</div>
			<div class="manage-list">
				<div class="manage-list-item" v-for="(item,index) in reviewVoteList " :key="item.id">
					<div class="info-bar">
						<div>{{item.contestMaster}}VS{{item.contestBranch}}（{{item.infoName}}）</div>
					</div>
					<div class="line"></div>
					<div class="info-row">
						支持幣種：{{item.symbol}}
					</div>
					<div>
						<div class="info-row ">
							贊成票數：
							<span class="number f16">
                        <i class="fa fa-thumbs-up"></i>{{precisionDivision(item.forVotes,8) }}/{{precisionDivision(item.quorumVotes,8) }}
                    </span>

						</div>
						<div class="info-row ">
							反對票數：
							<span class="number f16"><i class="fa fa-thumbs-down"></i>{{precisionDivision(item.againstVotes,8)}}</span>
						</div>

						<div class="info-row" >
							投票截止：
							<i class="fa fa-clock-o"></i><span>{{ voteCutTimeFormat(item.endTime) }}</span>
						</div>
						<div class="info-row" :class="(item.statue==2 || item.statue==3 ) && 'c-red'">
							投票狀態：
							{{voteStatusObject[item.statue]}}
							({{item.statue}})
						</div>
						<div class="info-row">發起時間：{{item.createTime}}</div>
						<div class="info-row">發 起 人：{{item.sponsor|token}}</div>
						<div class="info-row"></div>
					</div>
					<div class="line"></div>
					<div class="btn-group">
						<el-button  type="danger" size="mini" @click="actShowDialog(item.proposalId)">作廢</el-button>
					</div>
				</div>
			</div>
		</div>
		<div class="uc-body" v-else>
			非法用户
		</div>
		<!--******************************************* 结果填写弹层 ***********************************************-->

		<el-dialog
				title=""
				width="340px"
				top="calc(50vh - 250px)"
				:append-to-body="true"
				:visible.sync="visibleSettle"
				:before-close="onCloseResultWrite"
		>
			<div class="dialog-detail-module">
				<div class="module-title">作廢該投票+賽事</div>
				<div class="line"></div>
				<div class="module-wrap">
					<div class="v-row">
						<span>參賽隊伍：</span>
						<div class="con">
							{{voteObject.contestMaster}}
							<img src="@/assets/vs.svg" alt="">
							{{voteObject.contestBranch}}
						</div>
					</div>
				</div>
				<div class="line"></div>
				<div class="btn-group">
					<el-button
						type="danger"
						size="medium"
						icon="el-icon-warning" round :loading="submiting" :disabled="submiting"
						@click="actSettleResult(voteObject.proposalId,1)"
					>
						作廢
					</el-button>

				</div>
			</div>
		</el-dialog>
	</div>
</template>

<script>

	//数据
	import manageList from "./components/manageList";
	import breadCrumb from '../components/breadCrumb.vue'
	import { mixins } from '@/mixins/mixins'
	import { mixinsUtils } from '@/mixins/mixins.utils'
	import { mixinsManage } from "@/views/manage/js/manage.mixins";
	import { contestMixinsGlobal} from '@/views/contestHall/contest.mixins.global'
	import {
		apiVotingAnalysisServe
	} from "@/views/uc/manage/js/manage.user.lib";

	import util from "@/libs/util";
	import { mapGetters } from "vuex";
	import {apiToBeManageVote, tronDiscardProposal} from "./js/manage.user.lib";
	import { msgInterface, smartContractBroadcastCallback, smartContractConfirmCallback } from "@/libs/site.utils";

	const debounce = util.debounce(1000) //初始化个防抖对象

	//导出
	export default {
		name:"manageContestManage",
		components: { breadCrumb,manageList },
		mixins:[mixins,mixinsUtils,mixinsManage,contestMixinsGlobal],
		data () {
			return {
				/////////////////////////////////////////////////////////////////
				loading:false,
				visibleSettle: false,//弹层显示
				submiting    : false,//是否提交中
				timestampNow : 0,
				listDataCount: 0,//数量
				//////////////////////////////////////////////////////////////////
				//请求参数
				requestParameter: {
					sender: this.sender
				},
				//数据列表
				reviewVoteList:[],
				//基础数据对象,
				voteObject:{
					sportingInfo:{
						rs:[] //初始化这个值，以免出错
					}
				},
			}
		},
		computed:{
			...mapGetters(['isSuperUser']),
		},
		created () {
			this.pageInit()
		},
		mounted () {
		},
		methods:{
			//初始化
			pageInit(){
				if( this.isSuperUser ) {
					this.getToBeManageVote()//加载数据
				} else {
					this.$message.error('非法用户')
				}
			},
			//获取待复核结果的投票列表数据
			getToBeManageVote () {
				let that = this;
				apiToBeManageVote({
					...this.requestParameter
				}, (res) => {
					if (res.resultFlag) {
						this.listDataCount  = res.count
						this.reviewVoteList = res.data
						let _idArr =  this.reviewVoteList.reduce((ret,cur) => {
							ret.push(cur.sportingId)
							return ret
						},[])

					}
				})
			},


			/**
			 * 复核提交处理
			 * @param proposalId 投票id
			 * @param type 类型
			 */
			actSettleResult (proposalId,type) {
				let that = this;

				this.$confirm('確定執行操作嗎?', '提示', {
					confirmButtonText: '確定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.visibleSettle = false //關閉對話框
					msgInterface('作廢賽事', 0, 1);//等待钱包确认
					tronDiscardProposal(this.sender, proposalId,
						smartContractBroadcastCallback('作廢', '操作', (status, txid) => {
							that.submiting = false //恢復可提交
							if (status == 1) {
								apiVotingAnalysisServe({}, txid); //通知服務器根據hash爬新數據
								setTimeout(() => {
									that.getToBeManageVote()//加載數據
								}, 5000)
								setTimeout(() => {
									that.getToBeManageVote()//加載數據
								}, 10000)
							}
						}),
						smartContractConfirmCallback('作廢', '操作')
					);

				}).catch(() => {

				});
			},


			test(id){
				this.$notify({type:"success",title:"测试",message:id})
			},
			////////////////////////////////////////////////////////////////////////////////////////////////////////
			////////////////////////////////////////////////////////////////////////////////////////////////////////
			////////////////////////////////////////////////////////////////////////////////////////////////////////
			//刷新，筛选
			reFresh () {
				this.showLoading()
				debounce(()=> {
					this.getToBeManageVote()
					setTimeout(() => {
						this.hideLoading()
					},500)
				})
			},

			//显示操作层
			actShowDialog(id){
				let that = this;

				this.voteObject = this.reviewVoteList.find((item) => {
					if (parseInt(item.proposalId) == id) {
						that.voteObject = item;
						return item
					}
				})
				this.visibleSettle = true
			},

			//关闭结果填写,如果绑定了关闭回调，则要调用done()
			onCloseResultWrite(done){
				done()
			},
		}
	}
</script>

<style lang="less" scoped>
    /*公共变量*/
    @import '~@/assets/global.less';
    //单独控制弹层样式细节
    .dialog-detail-module {
        font-size: 16px;
    .module-wrap {
    .v-row {padding:3px 0;}
    }
    .btn-group{
    }
    }
    /************************************适应***************************************/
    @media screen and (max-width: @MINSCREEN){

    }
</style>
